<?php
function format_config($data) {
    foreach ($data as $k => $v) {
        $data[$k] = get_config_html($v);
    }
    return $data;
}

function get_config_html($v) {
    $html = '';
    $html.= "<tr><td class='title'>" . $v['title'] . "</td>";
    $html.="<td class='input {$v["name"]}'>";
    switch ($v['viewtype']) {
        case "string":
            $html.="<input type='text' name='{$v["name"]}' value='{$v["value"]}' style='width:400px;'/>";
            break;
        case "select":
            break;
        case "radio":
            $arr = explode(",", $v['viewvalue']);
            foreach ($arr as $m) {
                $n = explode("|", $m);
                $checked = $n[0] == $v['value'] ? "checked='checked'" : '';
                $html.="<li style='width:80px;float:left;'><input type='radio' name='{$v["name"]}' value='{$n[0]}' $checked/> {$n[1]}</li>";
            }
            break;
        case "checkbox";
            $arr = explode(",", $v['viewvalue']);
            $html.="<select name='{$v['name']}'";
            foreach ($arr as $m) {
                $n = explode("|", $m);
                $selected = $n[0] == $v['value'] ? "selected='selected'" : '';
                $html.="<option value='{$n[0]}' $selected/> {$n[1]}</option>";
            }
            $html.="</select>";
            break;
        case "textarea":
            $html.="<textarea  name='{$v["name"]}' style='width:400px;height:50px;'/>{$v["value"]}</textarea>";
            break;
    }
    $html.="</td><td class='msg'>{$v['msg']}</td>";
    $html.="<td class='var'>{\$hd.conf." . $v['name'] . "}</td></tr>";
    $v['html'] = $html;
    return $v;
}

?>
